package com.xinqing.test.LetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author:CHQ
 * @Date:2021/7/20 14:19
 * @Description
 */
public class PostorderTraversal {
    static ArrayList<Integer> list;

    public static void main(String[] args) {
        list = new ArrayList<>();
        TreeNode root = new TreeNode(1);
        TreeNode l = new TreeNode(2);
        TreeNode r = new TreeNode(3);
        root.left = l;
        root.right = r;
        test(root);

        for (Integer x : list) {
            System.out.print(x + " ");
        }
    }

    public static void test(TreeNode root) {
        if (root == null) {
            return;
        }

        test(root.left);
        test(root.right);
        list.add(root.val);

    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    public TreeNode(int val) {
        this.val = val;
    }

    @Override
    public String toString() {
        return "TreeNode={" +
                "val=" + val + "," +
                "left={" + left + "}" +
                "right={" + right + "}" +
                "}";
    }

}
